package com.example.administrator.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.administrator.myapplication.adapter.MyAdapter;


public class CitySelectActivity extends Activity {
    String[] citys = {"长沙市", "株洲市", "岳阳市", "湘潭市", "邵阳市", "娄底市", "衡阳市"};
    private ListView cityListView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_city);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        cityListView = findViewById(R.id.city_select_listView);
        cityListView.setAdapter(new MyAdapter(CitySelectActivity.this, citys));
    }

    private void initData() {

    }

    private void initEvent() {
        cityListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                intent.putExtra("data", citys[position]);
                setResult(1, intent);
                finish();
            }
        });

    }
}
